package gui.calendarview;

import java.awt.Color;
import java.awt.Component;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import no.ntnu.fp.model.ActivityModel;
import no.ntnu.fp.swingutil.CalendarTools;

public class MonthViewCellRenderer extends JLabel implements ListCellRenderer {
	
	private static final long serialVersionUID = 1L;
	
	private CalendarTools ct = new CalendarTools();
	
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		Date date = ((ActivityModel) list.getModel().getElementAt(index)).getStartDate();
		String dato = ct.printDate(date, false, true, true, false, false);
		this.setText( " " + dato + " " + value.toString());
		this.setBorder(BorderFactory.createLineBorder(Color.BLUE));
		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}
		setEnabled(list.isEnabled());
		setFont(list.getFont());
		setOpaque(true);
		return this;
	}

}
